/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import entities.CompanyAdquiredProfileFolderState;
import facades.CompanyProductFacade;
import facades.CountryFacade;
import facades.DesiredSalaryFacade;
import facades.EducationalLevelFacade;
import facades.EducationalStatusFacade;
import facades.JobDurationFacade;
import facades.JobPositionFacade;
import facades.LanguageFacade;
import facades.LanguageLevelFacade;
import facades.ProvinceFacade;
import facades.SectorFacade;
import facades.SexFacade;
import facades.TimeAvailabilityFacade;
import facades.TownFacade;
import entities.CompanyProduct;
import entities.Country;
import entities.DesiredSalary;
import entities.EducationalLevel;
import entities.EducationalStatus;
import entities.JobDuration;
import entities.JobPosition;
import entities.Language;
import entities.LanguageLevel;
import entities.Province;
import entities.Sector;
import entities.Sex;
import entities.TimeAvailability;
import entities.Town;
import facades.CompanyAdquiredProfileFolderStateFacade;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Named;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import qualifiers.ResourceList;

/**
 *
 * @author damfercer
 */
@Named(value = "resourcesBean")
@ApplicationScoped
public class ResourcesBean {
    @Inject
    private EducationalStatusFacade educationalStatusFacade;
    @Inject
    private SectorFacade sectorFacade;
    @Inject
    private JobDurationFacade jobDurationFacade;
    @Inject
    private CountryFacade countryFacade;
    @Inject
    private ProvinceFacade provinceFacade;
    @Inject
    private TownFacade townFacade;
    @Inject
    private SexFacade sexFacade;
    @Inject
    private EducationalLevelFacade educationalLevelFacade;
    @Inject
    private JobPositionFacade jobPositionFacade;
    @Inject
    private LanguageFacade languageFacade;
    @Inject
    private LanguageLevelFacade languageLevelFacade;
    @Inject
    private DesiredSalaryFacade desiredSalaryFacade;
    @Inject
    private TimeAvailabilityFacade timeAvailabilityFacade;
    @Inject
    private CompanyProductFacade companyProductFacade;
    @Inject
    private CompanyAdquiredProfileFolderStateFacade companyAdquiredProfileFolderStateFacade;
    
    private List<EducationalStatus> educationalStatuses;
    private List<Sector> sectors;
    private List<JobDuration> jobDurations;
    private List<Country> countries;
    //private List<Province> provinces;
    //private List<Town> towns;
    private List<Sex> sexs;
    private List<EducationalLevel> educationalLevels;
    private List<JobPosition> jobPositions;
    private List<Language> languages;
    private List<LanguageLevel> languageLevels;
    private List<DesiredSalary> desiredSalaries;
    private List<TimeAvailability> timeAvailabilities;
    private List<CompanyProduct> companyProducts;
    private Country spain;
    private List<CompanyAdquiredProfileFolderState>companyAdquiredProfileFolderState;
    /*private Map<Integer, Country> countriesMap;
    private Map<Integer, Province> provincesMap;
    private Map<Integer, Town> townsMap;*/
    /**
     * Creates a new instance of ResourcesBean
     */
    public ResourcesBean() {
    }
    
    @PostConstruct
    public void init(){
        /*countriesMap=new HashMap<Integer, Country>();
        provincesMap=new HashMap<Integer, Province>();
        townsMap=new HashMap<Integer, Town>();*/
        educationalStatuses=educationalStatusFacade.findAll();
        sectors=sectorFacade.findAll();
        jobDurations=jobDurationFacade.findAll();
        countries=countryFacade.findAll();  
        /*provinces=provinceFacade.findAll();
        towns=townFacade.findAll();*/
        sexs=sexFacade.findAll();
        educationalLevels=educationalLevelFacade.findAll();
        jobPositions=jobPositionFacade.findAll();
        languages=languageFacade.findAll();
        languageLevels=languageLevelFacade.findAll();
        desiredSalaries=desiredSalaryFacade.findAll();
        timeAvailabilities=timeAvailabilityFacade.findAll();
        companyProducts=companyProductFacade.findAll();
        companyAdquiredProfileFolderState=companyAdquiredProfileFolderStateFacade.findAll();
        spain=countryFacade.getSpain();
        Collections.sort(desiredSalaries);
        Collections.sort(jobDurations);
        Collections.sort(languageLevels);
        orderCountries();
    }
    public void orderCountries(){
        for (Country country : countries) {
            if(country.getProvinceList()!=null){
                List<Province> provincesOrder=country.getProvinceList();
                Collections.sort(provincesOrder);
                for (Province province : provincesOrder) {
                    if(province.getTownList()!=null){
                        List<Town> townsOrder=province.getTownList();
                        Collections.sort(townsOrder);
                        province.setTownList(townsOrder);
                        for (Town town : townsOrder) {
                           //townsMap.put(town.getIdTown(), town);
                        }
                    }
                    //provincesMap.put(province.getIdProvince(), province);
                }
                country.setProvinceList(provincesOrder);
            }
            //countriesMap.put(country.getIdCountry(), country);
        }
    }
    /*
    @Produces
    @ResourceList
    public Map<Integer,Country> getCountriesMap() {
        return countriesMap;
    }
    
    @Produces
    @ResourceList
    public Map<Integer,Province> getProvincesMap() {
        return provincesMap;
    }
    
    @Produces
    @ResourceList
    public Map<Integer,Town> getTownsMap() {
        return townsMap;
    }
    
    /**
     * @return the educationalStatuses
     */
    @Produces
    @ResourceList
    public List<EducationalStatus> getEducationalStatuses() {
        return educationalStatuses;
    }

    /**
     * @param educationalStatuses the educationalStatuses to set
     */
    public void setEducationalStatuses(List<EducationalStatus> educationalStatuses) {
        this.educationalStatuses = educationalStatuses;
    }
    
    public Date getMaxDate(){
        Calendar date = Calendar.getInstance();  
        date.setTime(new Date());  
        date.add(Calendar.YEAR,-18); 
        return date.getTime();
    }

    /**
     * @return the sectors
     */
    @Produces
    @ResourceList
    public List<Sector> getSectors() {
        return sectors;
    }

    /**
     * @param sectors the sectors to set
     */
    public void setSectors(List<Sector> sectors) {
        this.sectors = sectors;
    }

    /**
     * @return the jobDurations
     */
    @Produces
    @ResourceList
    public List<JobDuration> getJobDurations() {
        return jobDurations;
    }

    /**
     * @param jobDurations the jobDurations to set
     */
    public void setJobDurations(List<JobDuration> jobDurations) {
        this.jobDurations = jobDurations;
    }

    /**
     * @return the countries
     */
    @Produces
    @ResourceList
    public List<Country> getCountries() {
        return countries;
    }

    /**
     * @param countries the countries to set
     */
    public void setCountries(List<Country> countries) {
        this.countries = countries;
    }
//
//    /**
//     * @return the provinces
//     */
//    @Produces
//    @ResourceList
//    public List<Province> getProvinces() {
//        return provinces;
//    }
//
//    /**
//     * @param provinces the provinces to set
//     */
//    public void setProvinces(List<Province> provinces) {
//        this.provinces = provinces;
//    }
//
//    /**
//     * @return the towns
//     */
//    @Produces
//    @ResourceList
//    public List<Town> getTowns() {
//        return towns;
//    }
//
//    /**
//     * @param towns the towns to set
//     */
//    public void setTowns(List<Town> towns) {
//        this.towns = towns;
//    }

    /**
     * @return the sexs
     */
    @Produces
    @ResourceList
    public List<Sex> getSexs() {
        return sexs;
    }

    /**
     * @param sexs the sexs to set
     */
    public void setSexs(List<Sex> sexs) {
        this.sexs = sexs;
    }
        
    @Produces
    @ResourceList
    public List<CompanyAdquiredProfileFolderState> getCompanyAdquiredProfileFolderState() {
        return companyAdquiredProfileFolderState;
    }
    
    /**
     * @param companyAdquiredProfileFolderState the companyAdquiredProfileFolderState to set
     */
    public void setCompanyAdquiredProfileFolderState(List<CompanyAdquiredProfileFolderState> companyAdquiredProfileFolderState) {
        this.companyAdquiredProfileFolderState = companyAdquiredProfileFolderState;
    }

    /**
     * @return the educationalLevels
     */
    @Produces
    @ResourceList
    public List<EducationalLevel> getEducationalLevels() {
        return educationalLevels;
    }

    /**
     * @param educationalLevels the educationalLevels to set
     */
    public void setEducationalLevels(List<EducationalLevel> educationalLevels) {
        this.educationalLevels = educationalLevels;
    }

    /**
     * @return the jobPositions
     */
    @Produces
    @ResourceList
    public List<JobPosition> getJobPositions() {
        return jobPositions;
    }

    /**
     * @param jobPositions the jobPositions to set
     */
    public void setJobPositions(List<JobPosition> jobPositions) {
        this.jobPositions = jobPositions;
    }

    /**
     * @return the languages
     */
    @Produces
    @ResourceList
    public List<Language> getLanguages() {
        return languages;
    }

    /**
     * @param languages the languages to set
     */
    public void setLanguages(List<Language> languages) {
        this.languages = languages;
    }

    /**
     * @return the languageLevels
     */
    @Produces
    @ResourceList
    public List<LanguageLevel> getLanguageLevels() {
        return languageLevels;
    }

    /**
     * @param languageLevels the languageLevels to set
     */
    public void setLanguageLevels(List<LanguageLevel> languageLevels) {
        this.languageLevels = languageLevels;
    }

    /**
     * @return the desiredSalaries
     */
    @Produces
    @ResourceList
    public List<DesiredSalary> getDesiredSalaries() {
        return desiredSalaries;
    }

    /**
     * @param desiredSalaries the desiredSalaries to set
     */
    public void setDesiredSalaries(List<DesiredSalary> desiredSalaries) {
        this.desiredSalaries = desiredSalaries;
    }

    /**
     * @return the timeAvailabilities
     */
    @Produces
    @ResourceList
    public List<TimeAvailability> getTimeAvailabilities() {
        return timeAvailabilities;
    }

    /**
     * @param timeAvailabilities the timeAvailabilities to set
     */
    public void setTimeAvailabilities(List<TimeAvailability> timeAvailabilities) {
        this.timeAvailabilities = timeAvailabilities;
    }

    /**
     * @return the companyProducts
     */
    @Produces
    @ResourceList
    public List<CompanyProduct> getCompanyProducts() {
        return companyProducts;
    }

    /**
     * @param companyProducts the companyProducts to set
     */
    public void setCompanyProducts(List<CompanyProduct> companyProducts) {
        this.companyProducts = companyProducts;
    }

    /**
     * @return the spain
     */
    public Country getSpain() {
        return spain;
    }

    /**
     * @param spain the spain to set
     */
    public void setSpain(Country spain) {
        this.spain = spain;
    }
    
    public List<Object> createIterableList(Integer itemNumber){
        ArrayList<Object> arrayList=new ArrayList<Object>();
        for (int i = 0; i < itemNumber; i++) {
            arrayList.add(new Object());
        }
        return arrayList;
    }
}
